<template>
  <div class="app-container">
    <div class="title-icon">
      <i class="iconfont iconhelp" @click="preview"></i>
    </div>
    <el-row :gutter="24">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
          <el-form-item label="姓名" prop="nickName">
            <el-input
              v-model="queryParams.nickName"
              placeholder="请输入姓名"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="员工编号" prop="jobNo">
            <el-input
              v-model="queryParams.jobNo"
              placeholder="请输入员工编号"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="所属角色" prop="userRoles">
            <el-input
              v-model="queryParams.userRoles"
              placeholder="请输入所属角色"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
            <!-- <el-select
              v-model="queryParams.userRoles"
              placeholder="请选择"
              clearable
              size="small"
              style="width: 240px"
            >
              <el-option
                v-for="dict in roleOptions"
                :key="dict.roleName"
                :label="dict.roleName"
                :value="dict.roleName"
              />
            </el-select>-->
          </el-form-item>
          <el-form-item label="所属项目负责人" prop="leaders" label-width="120px">
            <el-input
              v-model="queryParams.leaders"
              placeholder="请输入所属项目负责人"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select
              v-model="queryParams.status"
              placeholder="用户状态"
              clearable
              size="small"
              style="width: 240px"
            >
              <el-option
                v-for="dict in statusOptionsQuery"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="账号" prop="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入账号"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="手机号码" prop="phonenumber">
            <el-input
              v-model="queryParams.phonenumber"
              placeholder="请输入手机号码"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:user:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
            >导出</el-button>
          </el-col>
        </el-row>

        <el-table
          stripe
          v-loading="loading"
          :data="userList"
          @sort-change="tableSortChange"
          :default-sort="{prop: 'status', order: 'descending'}"
        >
          <el-table-column
            label="姓名"
            align="center"
            width="150"
            prop="nickName"
            :show-overflow-tooltip="true"
            :sort-orders="['ascending', 'descending']"
            sortable="custom"
          />
          <el-table-column
            label="员工编号"
            align="center"
            width="150"
            prop="jobNo"
            :show-overflow-tooltip="true"
            :sort-orders="['ascending', 'descending']"
            sortable="custom"
          />
          <el-table-column
            label="账号"
            align="center"
            width="150"
            prop="userName"
            :show-overflow-tooltip="true"
            :sort-orders="['ascending', 'descending']"
            sortable="custom"
          />
          <el-table-column
            label="手机号码"
            align="left"
            prop="phonenumber"
            width="150"
            :sort-orders="['ascending', 'descending']"
            sortable="custom"
          />
          <el-table-column label="所属角色" align="left" prop="userRoles" />
          <el-table-column label="所属项目负责人" align="center" prop="leaders" />
          <el-table-column
            label="人事主管部门"
            align="center"
            prop="personnelDept"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="状态"
            align="center"
            width="120"
            prop="status"
            :sort-orders="['ascending', 'descending']"
            sortable="custom"
          >
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status=='0'" type="success" disable-transitions>正常</el-tag>
              <el-tag v-else-if="scope.row.status=='1'" type="info" disable-transitions>停用</el-tag>
              <el-tag v-else type="warning" disable-transitions>未启用</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="180"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:user:edit']"
              >编辑</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <!--新增用户 -->
    <el-dialog :title="title" :visible.sync="openAddUser" @close="cancelAddUser" width="60%">
      <el-form
        :model="addUserQueryParams"
        ref="addUserQueryForm"
        :rules="addUserRules"
        :inline="true"
        label-width="88px"
      >
        <el-form-item label="姓名" prop="userName">
          <el-input
            v-model="addUserQueryParams.userName"
            placeholder="请输入姓名"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>

        <el-form-item label="员工编号" prop="jobNo">
          <el-input
            v-model="addUserQueryParams.jobNo"
            placeholder="请输入员工编号"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="addUserHandleQuery">查询</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="addUserResetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="addUserList">
        <el-table-column
          label="姓名"
          align="center"
          width="150"
          prop="userName"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="员工编号"
          align="center"
          width="150"
          prop="jobNo"
          :show-overflow-tooltip="true"
        />
        <el-table-column label="手机号码" align="center" prop="phoneNumber" width="150" />
        <el-table-column
          label="人事主管部门"
          align="center"
          prop="personnelDept"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          label="操作"
          align="center"
          width="180"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleAddUser(scope.row)"
              v-hasPermi="['system:user:edit']"
            >添加</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelAddUser">取 消</el-button>
      </div>
    </el-dialog>

    <!--修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%">
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="nickName">
              <el-input :disabled="true" v-model="form.nickName" placeholder="请输入用户昵称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="人事主管部门" prop="personnelDept">
              <el-input :disabled="true" v-model="form.personnelDept" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="员工编号" prop="jobNo">
              <el-input :disabled="true" v-model="form.jobNo" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号码" prop="phonenumber">
              <el-input v-model="form.phonenumber" placeholder="请输入手机号码" maxlength="11" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="账号" prop="userName">
              <el-input :readonly="isNameReadonly"  type="text" @focus="focusNameChange" v-model="form.userName" placeholder="请输入账号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户密码" prop="password">
              <el-input :readonly="isPassReadonly" type="text" @focus="focusPassChange" v-model="form.password" placeholder="请输入用户密码" show-password clearable />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户状态" prop="status">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="dict in form.statusOptions"
                  :key="dict.dictValue"
                  :label="dict.dictValue"
                >{{dict.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属项目负责人" prop="leaders">
              <el-input :disabled="true" v-model="form.leaders" />
            </el-form-item>
          </el-col>
          <!-- 
            <el-col :span="12">
            <el-form-item label="角色">
              <el-select v-model="form.roleIds" multiple placeholder="请选择">
                <el-option
                  v-for="item in roleOptions"
                  :key="item.roleId"
                  :label="item.roleName"
                  :value="item.roleId"
                  :disabled="item.status == 1"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>-->
          <el-col :span="8">
            <el-form-item label="角色">
              <el-checkbox-group v-model="form.roleIds">
                <el-checkbox
                  style="display:block"
                  v-for="item in roleOptions"
                  :label="item.roleId"
                  :key="item.roleId"
                >{{item.roleName}}</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>

          <el-col v-for="item in roleOptions" :key="item.roleId" :span="16" style="height:36px;">
            <!-- 业务所技术负责人 -->
            <el-form-item v-if="item.roleKey == 'institute_principal'">
              <treeselect
                v-model="form.instituteDeptIds"
                :options="deptOptions1"
                :multiple="true"
                :flat="true"
                placeholder="请选择组织部门"
              />
            </el-form-item>
            <!-- 业务部门技术负责人 -->
            <el-form-item v-if="item.roleKey == 'dept_ principal'">
              <treeselect
                v-model="form.deptIds"
                :options="deptOptions1"
                :multiple="true"
                :flat="true"
                placeholder="请选择组织部门"
              />
            </el-form-item>
            <!-- 专业技术负责人 -->
            <el-form-item v-else-if="item.roleKey == 'major_ principal'">
              <treeselect
                v-model="form.businessTypeIds"
                :options="businesstypes"
                :multiple="true"
                :flat="true"
                :disable-branch-nodes="true"
                placeholder="请选择业务分管类别"
              />
            </el-form-item>
            <!-- 公章管理员 -->
            <el-form-item v-else-if="item.roleKey == 'cachet_manager'">
              <treeselect
                v-model="form.cachetDeptIds"
                :options="deptOptions2"
                :multiple="true"
                :flat="true"
                placeholder="请选择组织部门"
              />
            </el-form-item>
            <!-- 业务分管副总 -->
            <el-form-item v-else-if="item.roleKey == 'business_leader'">
              <treeselect
                v-model="form.businessDeptIds"
                :options="deptOptions3"
                :multiple="true"
                :flat="true"
                placeholder="请选择组织部门"
              />
            </el-form-item>
            <!-- 业务部门负责人 -->
            <el-form-item v-else-if="item.roleKey == 'dept_leader'">
              <treeselect
                v-model="form.deptLeaderIds"
                :options="deptOptions4"
                :multiple="true"
                :flat="true"
                placeholder="请选择组织部门"
              />
            </el-form-item>

            <!-- 业务所负责人 -->
            <el-form-item v-else-if="item.roleKey == 'institute_leader'">
              <treeselect
                v-model="form.deptInstituteLeaderIds"
                :options="deptOptions4"
                :multiple="true"
                :flat="true"
                placeholder="请选择组织部门"
              />
            </el-form-item>

            <el-form-item v-else></el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="备注">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="canClick">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 预览 -->
    <el-dialog :visible.sync="openPreview" width="80%">
      <iframe :src="manualPreviewUrl" frameborder="0" width="100%" height="700px"></iframe>
    </el-dialog>
  </div>
</template>

<script>
import {
  listUser,
  getUser,
  delUser,
  addUser,
  updateUser,
  exportUser,
  resetUserPwd,
  changeUserStatus,
  importTemplate,
  editPassword,
  addUserList,
  checkUser,
} from "@/api/system/user";
import { deptTreeSelect } from "@/api/system/organization";
import { optionselectRoles } from "@/api/system/role";
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { treeselect } from "@/api/system/business_category";

export default {
  name: "User",
  components: { Treeselect },
  data() {
    return {
      manualPreviewUrl: null,
      openPreview: false,
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: null,
      addUserList: null,
      isNameReadonly: true,
      isPassReadonly: true,
      // 弹出层标题
      title: "",
      // 部门树选项
      deptOptions1: undefined,
      deptOptions2: undefined,
      deptOptions3: undefined,
      deptOptions4: undefined,
      businesstypes: undefined,
      canClick:false,
      // 是否显示弹出层
      open: false,
      // 是否显示新增用户弹出层
      openAddUser: false,
      // 部门名称
      deptName: undefined,
      // 默认密码
      initPassword: undefined,
      // 日期范围
      dateRange: [],
      // 状态数据字典
      statusOptions: [
        {
          dictValue: "0",
          dictLabel: "正常",
        },
        {
          dictValue: "1",
          dictLabel: "停用",
        },
      ],
      statusOptionsQuery: [
        {
          dictValue: "0",
          dictLabel: "正常",
        },
        {
          dictValue: "1",
          dictLabel: "停用",
        },
        {
          dictValue: "2",
          dictLabel: "未启用",
        },
      ],
      // 角色选项
      roleOptions: [],
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/user/importData",
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        nickName: undefined,
        phonenumber: undefined,
        status: undefined,
        deptId: undefined,
        jobNo: undefined,
        userRoles: undefined,
        leaders: undefined,
      },
      // 添加用户查询参数
      addUserQueryParams: {
        pageNum: 1,
        pageSize: 10,
        jobNo: undefined,
        userName: undefined,
      },
      addUserRules: {
        userName: [
          { required: true, message: "姓名不能为空", trigger: "blur" },
        ],
        jobNo: [
          { required: true, message: "员工编号不能为空", trigger: "blur" },
        ],
      },
      // 表单校验
      rules: {
        userName: [
          { required: true, message: "账号不能为空", trigger: "blur" },
        ],
        status: [
          { required: true, message: "请选择用户状态", trigger: "change" },
        ],
        phonenumber: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
          {
            pattern: /^\d{11}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    },
  },
  created() {
    this.getRoleOptions();
    this.getList();
    this.getBusinesstypes();
    this.getDeptTreeSelect();
    this.getTreeselect();
    this.getConfigKey("sys.user.initPassword").then((response) => {
      this.initPassword = response.msg;
    });
  },
  methods: {
    tableSortChange(column) {
      this.queryParams.pageNum = 1;
      if (column.order === "descending") {
        this.queryParams.sortBy = column.prop;
        this.queryParams.order = "desc";
      } else {
        this.queryParams.sortBy = column.prop;
        this.queryParams.order = "asc";
      }
      this.getList();
    },
    getBusinesstypes() {
      treeselect().then((response) => {
        this.businesstypes = this.handleTreeString(response.data, "menuId");
      });
    },
    /** 查询部门下拉树结构 */
    getDeptTreeSelect() {
      deptTreeSelect().then((response) => {
        this.deptOptions1 = JSON.parse(
          JSON.stringify(response.data).replace(/isDisabled/g, "checkbox")
        );
        this.deptOptions2 = this.deptOptions1;
        this.deptOptions3 = this.deptOptions1;
        this.deptOptions4 = this.deptOptions1;
      });
    },
    getRoleOptions() {
      optionselectRoles().then((response) => {
        this.roleOptions = response.data;
      });
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    getAddUserList() {
      this.loading = true;
      addUserList(this.addUserQueryParams).then((response) => {
        this.addUserList = response.rows;
        this.loading = false;
      });
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      /*treeselect().then(response => {
        this.deptOptions = response.data;
      });*/
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.getList();
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$confirm(
        '确认要"' + text + '""' + row.userName + '"用户吗?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return changeUserStatus(row.userId, row.status);
        })
        .then(() => {
          this.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.status = row.status === "0" ? "1" : "0";
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancelAddUser() {
      this.openAddUser = false;
      this.reset();
      this.addUserList = [];
      this.addUserQueryParams = {
        pageNum: 1,
        pageSize: 10,
        jobNo: undefined,
        userName: undefined,
      };
    },
    // 表单重置
    reset() {
      this.form = {
        userId: undefined,
        deptId: undefined,
        userName: undefined,
        nickName: undefined,
        password: undefined,
        jobNo: undefined,
        phonenumber: undefined,
        personnelDept: undefined,
        globalId: undefined,
        bpmUserId: undefined,
        status: "0",
        remark: undefined,
        roleIds: [],
        instituteDeptIds: [],
        deptIds: [],
        cachetDeptIds: [],
        businessTypeIds: [],
        businessDeptIds: [],
        deptLeaderIds: [],
        deptInstituteLeaderIds: [],
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    addUserHandleQuery() {
      this.$refs["addUserQueryForm"].validate((valid) => {
        if (valid) {
          this.addUserQueryParams.page = 1;
          this.getAddUserList();
        }
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    addUserResetQuery() {
      this.dateRange = [];
      this.addUserList = [];
      this.resetForm("addUserQueryForm");
      //this.addUserHandleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.openAddUser = true;
      this.title = "添加用户";
      //this.reset();
      //this.getTreeselect();
      /*getUser().then(response => {
        this.roleOptions = response.roles;
        this.open = true;
        this.title = "添加用户";
        this.form.password = this.initPassword;
      });*/
    },
    handleAddUser(row) {
      this.canClick=false;
      console.log(row.jobNo.substring(0, 3));
      if (row.jobNo.substring(0, 3) !== "H04") {
        this.$message({
          showClose: true,
          message: "员工编号未正式生成,请联系人事部门！",
          type: "warning",
        });
      } else {
        checkUser(row.jobNo).then((res) => {
          if (res.code === 200 && res.msg === "1") {
            this.reset();
            this.getRoleOptions();
            this.form.nickName = row.userName;
            this.form.phonenumber = row.phoneNumber;
            this.form.personnelDept = row.personnelDept;
            this.form.jobNo = row.jobNo;
            this.form.bpmUserId = row.ObjectID;
            this.form.globalId = row.globalId;
            this.open = true;
            this.title = "添加用户";

            if (row.idNumber && row.idNumber.length > 6) {
              this.form.password = row.idNumber.substring(
                row.idNumber.length - 6
              );
            } else {
              this.form.password = this.initPassword;
            }

            // this.form.password = this.initPassword;
            this.form.statusOptions = this.statusOptions;
          } else {
            this.$message({
              showClose: true,
              message:
                "员工编号为" + row.jobNo + "的用户已存在，请勿重复添加！",
              type: "warning",
            });
          }
        });
      }
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.form.status = undefined;
      this.getTreeselect();
      const userId = row.userId;
      getUser(userId).then((response) => {
        this.form = response.data;
        this.roleOptions = response.roles;
        this.form.roleIds = response.roleIds;
        if (response.instituteDeptIds) {
          this.form.instituteDeptIds = response.instituteDeptIds;
        }
        if (response.deptIds) {
          this.form.deptIds = response.deptIds;
        }

        if (response.businessTypeIds) {
          this.form.businessTypeIds = response.businessTypeIds;
        }

        if (response.cachetDeptIds) {
          this.form.cachetDeptIds = response.cachetDeptIds;
        }

        if (response.businessDeptIds) {
          this.form.businessDeptIds = response.businessDeptIds;
        }

        if (response.deptLeaderIds) {
          this.form.deptLeaderIds = response.deptLeaderIds;
        }

        if (response.deptInstituteLeaderIds) {
          this.form.deptInstituteLeaderIds = response.deptInstituteLeaderIds;
        }

        if (response.bpmUserId) {
          this.form.bpmUserId = response.bpmUserId;
        }

        this.open = true;
        this.title = "修改用户";
        this.form.password = undefined;
        this.form.statusOptions = this.statusOptions;
        if (response.data.status === "2") {
          this.form.status = undefined;
        }
        /*if (!this.form.password) {
          this.form.password = this.initPassword;
        }*/
      });
    },
    focusNameChange(){
      this.isPassReadonly = true;
      this.isNameReadonly = false;
    },
    focusPassChange(){
      this.isNameReadonly = true;
      this.isPassReadonly = false;
    },
    /** 重置密码按钮操作 */
    handleResetPwd(row) {
      this.$prompt('请输入"' + row.userName + '"的新密码', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(({ value }) => {
          resetUserPwd(row.userId, value).then((response) => {
            if (response.code === 200) {
              this.msgSuccess("修改成功，新密码是：" + value);
            } else {
              this.msgError(response.msg);
            }
          });
        })
        .catch(() => {});
    },
    /** 提交按钮 */
    submitForm: function () {
     var $this = this;
      this.addUserList = [];
      this.addUserQueryParams = {
        pageNum: 1,
        pageSize: 10,
        jobNo: undefined,
        userName: undefined,
      };
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.userId != undefined) {
            this.canClick=true;
            updateUser(this.form).then((response) => {
              if (response.code === 200) {
                this.canClick=false;
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.canClick=false;
                this.msgError(response.msg);
              }
            }).catch(function () { 
              debugger
              $this.canClick=false;
            });
          } else {
            this.canClick=true;
            addUser(this.form).then((response) => {
              if (response.code === 200) {
                this.canClick=false;
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.canClick=false;
                this.msgError(response.msg);
              }
            }).catch(function () { 
              $this.canClick=false;
            });
          }
        }
      });
    },
    preview() {
      this.openPreview = true;
      this.manualPreviewUrl = `${this.previewUrl}${encodeURIComponent(
        `${this.operationManual}系统管理/用户管理.xlsx`
      )}&name=${encodeURIComponent("用户管理.xlsx")}`;
    } /** 导出按钮操作 */,
    handleExport() {
      exportUser(this.addDateRange(this.queryParams, this.dateRange)).then((res) => {
        if (res.code === 200) {
          this.download(res.msg);
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.title-icon {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  cursor: pointer;
  margin-bottom: 10px;
  .iconhelp {
    font-size: 18px;
  }
}
</style>